import string
import urllib.request
from urllib.parse import quote
from bs4 import BeautifulSoup
def nospace(world):
    return world.replace("","").replace("\n","")


city = input("请输入城市：")
code = {
    '北京': '530',
    '上海': '538',
    '广州': '763',
    '深圳': '765',
    '天津': '531',
    '武汉': '736',
    '西安': '854',
    '成都': '801',
    '沈阳': '599',
    '南京': '635',
    '杭州': '653',
    '苏州': '639',
    '重庆': '551',
    '长沙': '749',
    '厦门': '682',
    '南昌': '691'
}
city = code[city]
jobName = input("请输入相关岗位：")
url = "https://sou.zhaopin.com/?jl="+city+"&kw"+jobName+"&p=1"
url = quote(url,safe=string.printable)
# 发送http请求
print(url)
resp = urllib.request.urlopen(url)

content = resp.read().decode("utf-8")

soup = BeautifulSoup(content,"lxml")
# 接下来存放想要的元素

jobList = soup.select(".job list-box__item")
job_list = []
for job in jobList:
    job_dic = {}
    # get_text()
    # getText()
    job_name = job.select(".job info__name")[0].get_text()
    job_sal = job.select(".jobinfo__salary")[0].get_text()
    job_sal=nospace(job_sal)
    if '天' in job_sal:
        job_sal = int(job_sal.split("-")[0]) * 30
    elif '千' in job_sal:
        job_sal = int(job_sal.split("千")[0]) * 1000
    elif '万' in job_sal:
        job_sal = float(job_sal.split("千")[0]) * 10000
    else:
        job_sal = 5000
    job_msg = job.select(".jobinfo__other-info-item")
    job_place = nospace(job_msg[0].getText)
    job_exp = nospace(job_msg[0].getText)
    job_education = nospace(job_msg[3].getText())
    job_dic['job_name'] = job_name
    job_dic['job_sal'] = job_sal
    job_dic['job_place'] = job_place
    job_dic['job_exp'] = job_exp
    job_dic['job_education'] = job_education
    job_list.append(job_dic)
for i in job_list:
    print(i)


